home *** CD-ROM | disk | FTP | other *** search
- // POLYMRPH.CPP - Is an example of how you can use the GENTREE program
- // to build you own custom applications.
- // Copyright (c) Paul Kimmel 1994
- // All Rights Reserved
-
- /***********************************************************************
- GENTREE - Lets you design your own customized OS commands. GENTREE simply
- traverses a DOS tree given a starting path and the res is up to you.
- Have you ever wanted to delete all *.BAK files on a disk? Well with
- GENTREE you can run. For example, executing GENTREE with the following
- arguments: GENTREE C: DEL *.BAK will search the entire disk executing
- the program DEL with arguments *.BAK. Simply follow the syntax required
- by GENTREE and it will do whatever you want it to.
-
- SYNTAX: gentree path prog_name arg1,arg2,arg3...
- Where path is any starting DOS path (e.g. C:, C:\DOS, D:\DOC)
- Where prog_name is any non-TSR executable, command, or batch program
- Where arg1,arg2 etc... are arguments you want that program (progr_name)
- to use as its arguments.
-
- The second way to use GENTREE is with the source code. The sample executable
- program bundled with GENTREE does what is mentioned above. But provide
- GENTREE with your own function and it becomes something completely new.
-
- Just follow the example in the source code adding your function argument
- and compile and link.
-
- GENTREE is available in PASCAL for 19.95 + shipping and handling.
- *************************************************************************/
-
- #include "gentree.h"
-
- #include <dos.h>
- #include <dir.h>
- #include <process.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <mem.h>
-
-
- const int MAX_COMMAND_LEN = 129; // dos limitation!
- char command[ MAX_COMMAND_LEN ];
-
- char pathName[ MAX_COMMAND_LEN ];
-
-
- // The function gentree calls
- void PolyMorph()
- {
- system( command );
- }
-
- void NormalizePathName( char* pname )
- {
- int j=0;
-
- for( int i=0; i<strlen( pname ); i++ ){
-
- if( pname[i] == '\\' ){
- pathName[j++] = '\\';
- }
- pathName[ j++ ] = pname[i];
- }
- }
-
-
- // Build the commands for the PolyMorph function
- void BuildCommand( int count, char* args[] )
- {
-
- memset( command, (int) 'P', MAX_COMMAND_LEN);
- command[ MAX_COMMAND_LEN - 1] = '\0';
-
- if ( count >= 2 ){
- strcpy( command, args[2] );
- strcat( command, " ");
-
-
- for( int i=3; i<count; i++ ){
- strcat( command, args[i] );
- strcat( command, " ");
- }
- }
- }
-
-
-
- // sample usage of the gentree functions
-
- void main( int argc, char* argv[] )
- {
- struct ffblk ffblk;
-
- if( argc < 2 ){
- printf( "syntax: gentree [drive:\][dir] prog_name args,...\n" );
- return;
- }
-
- NormalizePathName( argv[1] );
-
- if( !findfirst( pathName, &ffblk, FA_DIREC )) {
- printf( "starting directory %s not found\n", argv[1] );
- return;
- }
-
- BuildCommand( argc, argv );
-
- printf ("entered: %s \n", command );
-
- GenTree( PolyMorph, argv[1] );
- }
-